<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2024/4/9
  Time: 15:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="static/layui/css/layui.css">
</head>
<body>
<form id="formId" method="post">
    用户名：<input type="text" name="name"><br>
    密码：<input type="password" name="password"><br>
    验证码：<input type="text" name="code"> <img id="verifyCodeId" onclick="refresh()" src="/verifyCode"><br>
    <input type="button" onclick="submitForm()" value="登录">
</form>

<script src="/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/mylayer.js" type="text/javascript" charset="utf-8"></script>
<script>
    function refresh() {
        $('#verifyCodeId').attr('src', '/verifyCode?' + Math.random());
    }

    function submitForm() {
        $.post(
            '/user?method=login',
            $('#formId').serialize(), // {"name":"zhansgan","password":"1234"}
            function (result) {
                console.log(result);
                if (result.code == 0) {
                    mylayer.okUrl(result.msg, '/');
                } else {
                    mylayer.errorMsg(result.msg);
                }
            },
            'json'
        );
    }
</script>
</body>
</html>
